//for tinyriscv rib bus peripheral
//#define GPIO_CTRL      *((volatile unsigned int *)0x40000000)
//#define GPIO_ODR      *((volatile unsigned int *)0x40000004)

//for my peripheral
#define GPIO_ODR      *((volatile unsigned int *)0x10000000)
#define UART_TXD      *((volatile unsigned int *)0x10000040)
#define UART_RXD      *((volatile unsigned int *)0x10000040)
#define UART_STATUS   *((volatile unsigned int *)0x10000044)
#define TIMER_CTRL    *((volatile unsigned int *)0x10000080)
#define TIMER_COUNTER *((volatile unsigned int *)0x10000084)
#define TIMER_TOP     *((volatile unsigned int *)0x10000088)

int gValue;
int main(){
    unsigned int i;
    gValue = 1;
    GPIO_ODR = gValue;
    TIMER_TOP = 27000000;
    TIMER_CTRL = 0x01;
    while (1){
        GPIO_ODR = GPIO_ODR + 1;
//        GPIO_ODR = TIMER_COUNTER>>24;
        while (!(TIMER_CTRL&0x02)) {
            //wait for timeout
        }
        TIMER_CTRL = 0x01;
/*
        for (i=0;i<1500000;i++){
        }
*/
    }
    /*
    //check uart rx
    while (1){
        if ((UART_STATUS&0x01) ){
            UART_TXD = UART_RXD;
        }
    }
    */

    //check gpio
    /*
    while(1)    {
      GPIO_ODR = GPIO_ODR + 1;

      for (i=0;i<1500000;i++){
      }
    }
    */
    /*
    TIMER_CTRL = 0;
    TIMER_TOP =27000000-1; //1 second. core_clk = 27MHz
    TIMER_CTRL = 1;
    GPIO_ODR = TIMER_CTRL;

    while(1){
    }
*/

/*
    while(1)    {
      i = TIMER_COUNTER>>20;
//      gValue ++;
//      GPIO_ODR = gValue;
//      UART_TXD = gValue;
      GPIO_ODR = i;
      UART_TXD = i;

      for (i=0;i<1500000;i++){

      }

 //      TIMER_TOP =27000000-1; //1 second. core_clk = 27MHz
 //     TIMER_CTRL = 0x5; //clear timeout flag and enable
 //     while ((TIMER_CTRL&0x4) == 0 ){ //wait for timeout
 //     }
    }
*/
}
